package com.smile.ye.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile.ye.data.dto.ProductMenuCreateDto;
import com.smile.ye.data.dto.ProductMenuQueryDto;
import com.smile.ye.data.dto.ProductMenuUpdateDto;
import com.smile.ye.data.entity.ProductMenuEntity;
import com.smile.ye.mapper.ProductMenuMapper;
import com.smile.ye.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
@Service
public class ProductMenuService {
    @Autowired
    ProductMenuMapper mapper;

    public Result query(ProductMenuQueryDto dto){
        IPage<ProductMenuEntity> page = new Page(dto.getPage(), dto.getSize());
        LambdaQueryWrapper<ProductMenuEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(!StringUtils.isBlank(dto.getMenu()), ProductMenuEntity::getMenu, dto.getMenu());
        mapper.selectPage(page,wrapper);
        return Result.build(page);
    }

    public Result queryById(String id) {
        System.out.println("queid");
        ProductMenuEntity item = mapper.selectById(id);
        return Result.build(item);
    }
    public Result create(ProductMenuCreateDto dto){
        System.out.println("created");
        mapper.insert(dto);
        return Result.build();
    }

    public Result update(String id,ProductMenuUpdateDto dto){
        System.out.println("up");
        mapper.updateById(dto);
        return Result.build();
    }

    public Result remove(String id){
        System.out.println("delete");
        mapper.deleteById(id);
        return Result.build();
    }


}
